﻿using Microsoft.Practices.Unity;
using Microsoft.Practices.Prism.Logging;
using System.Windows.Input;
using System;
using Gwn.Library.MvpVm.Interfaces;

namespace Gwn.Library.MvpVm.Extensions
{
    /// <summary>
    /// 
    /// </summary>
    public static class UnityCommandExtension
    {
        /// <summary>
        /// Resolves the command.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="commandParameter">The command parameter.</param>
        /// <returns></returns>
        public static IPresenterCommand ResolveCommand(this IUnityContainer container, object commandParameter)
        {
            try
            {
                var command = container.Resolve<IPresenterCommand>(commandParameter.ToString());
                return command;
            }
            catch (Exception ex)
            {
                container.Resolve<ILoggerFacade>()
                    .Log("The command [{0}] has not been registerd with ICommand", commandParameter);

                return null;
            }

        }
    }
}
